package Assignment;

public class Test7 {
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6,7,8,9};
        int[] newArr = new int[arr.length];

        //奇数要存放的位置
        int start = 0;
        //偶数要存放的位置
        int end = arr.length-1;

        for (int i = 0, j = arr.length - 1; i < arr.length; i++) {
            if (arr[i] % 2 != 0) {
                //如果是奇数就往左边存放
                newArr[start] = arr[i];
                //存放之后索引向右移动
                start++;
            } else {
                //如果是偶数数就往右边边存放
                newArr[end] = arr[i];
                //存放之后索引向左移动
                end--;
            }
        }


        for (int i = 0; i < newArr.length; i++) {
            System.out.print(newArr[i] + " ");
        }
    }
}
